package com.skh.linkedlist;

/**
 * @Author: skh
 * @Date: 2019/6/11 15:47
 * @Description: 83. 删除排序链表中的重复元素
 */
public class DeleteDuplicates {

    /*
    给定一个排序链表，删除所有重复的元素，使得每个元素只出现一次。

    示例 1:

    输入: 1->1->2
    输出: 1->2
    示例 2:

    输入: 1->1->2->3->3
    输出: 1->2->3

     */

    public ListNode deleteDuplicates(ListNode head) {

       ListNode current = head;

        while (current != null && current.next != null) {
            if (current.next.val == current.val) {
                current.next = current.next.next;
            }else {
                current = current.next;
            }
        }

        return head;
    }

}
